package com.ttsx.controller.admin;

import com.ttsx.core.common.result.Result;
import com.ttsx.pojo.dto.auth.AccountLoginDTO;
import com.ttsx.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author wb
 * @since 2025-03-02
 */

@RestController
@RequestMapping("admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    public Result<?> login(@Valid @RequestBody AccountLoginDTO loginDTO) {
        return Result.success(adminService.login(loginDTO));
    }

    @GetMapping("/captcha")
    public Result<String> captcha(@RequestParam("randomStr") String randomStr) {
        return Result.success(adminService.genCaptcha(randomStr));
    }

    @GetMapping("/info")
    public Result<?> info(@RequestHeader("Authorization") String token) {
        return Result.success(adminService.info(token));
    }

    @GetMapping("/logout")
    public Result<?> logout(@RequestHeader("Authorization") String token) {
        return adminService.logout(token) ? Result.success() : Result.failure();
    }
}
